package efg.library.EJB;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "customer", schema = "abc_library")
public class Customer {   
	@Id
	@Column(name = "customer_name")
	private String name = null;
	@Column(name = "customer_credits")
	private int credits = 0;
	@OneToMany(mappedBy = "lendTo")
	private Set<Book> books = new HashSet<Book>();

	public String getName()
	{
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	int getCredits()
	{
		return credits;
	}

	void setCredits(int newCredits)
	{
		credits = newCredits;
	}

	Set<Book> getBooks()
	{
		return books;
	}

	void addBook(Book book)
	{
		books.add(book);
	}

	void removeBook(Book book)
	{
		books.remove(book);
	}

	@Override
	public String toString()
	{
		String ret =  "[Customer: "+name;
		for (Book book : books)
		{
			ret += (" "+book.getTitle());
		}
		return "customer"; //ret +"]";
	}
}